package com.example.snowliwork.activity;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.widget.ViewPager2;

import com.example.snowliwork.PageAdapter;
import com.example.snowliwork.PlanetGridAdapter;
import com.example.snowliwork.R;
import com.example.snowliwork.Shop;
import com.example.snowliwork.fragment.BagFragment;
import com.example.snowliwork.fragment.FoodFragment;
import com.example.snowliwork.fragment.InfantFragment;
import com.example.snowliwork.fragment.RecommendFragment;
import com.example.snowliwork.fragment.StoreFragment;
import com.example.snowliwork.fragment.UnderwearFragment;
import com.example.snowliwork.fragment.WomenwearFragment;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;

import java.util.ArrayList;
import java.util.List;

public class RecommendActivity extends AppCompatActivity {

//视图内容的展示
    //gridview展示页面
    private GridView gvShop;
    //商品数据源
    private List<Shop> shops;
    //声明商品适配器对象
    private PlanetGridAdapter shopAdapter;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.recomment_tablayout_activity);

        //获取控件对象
        getViews();


        //初始化子页面数据资源
        initPages();



        //实例化planeGridAdapter对象
        shopAdapter = new PlanetGridAdapter(
                this,
                R.layout.infant_tablayout_activity,
                shops
        );
        //给用于显示商品信息的gridview绑定适配器
        gvShop.setAdapter(shopAdapter);
        //注册监听器
        setListener();





    }

    //注册监听器
    private void setListener() {
        gvShop.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Log.i("MainActivity",shops.get(position).toString());
            }
        });

    }

    private void getViews() {

        //获取GridView空间对象
        gvShop = findViewById(R.id.gv_plant);


    }

    private void initPages() {

        //初始化商品数据源
        shops = new ArrayList<>();
        //添加商品数据
        Shop fireworks = new Shop(
                R.drawable.fireworks,
                "包邮微瑕蜡烛花烛20厘米",
                "退货包运费 急速退款",
                "￥13"
        );
        shops.add(fireworks);
        Shop gril = new Shop(
                R.drawable.gril,
                "女童裤子 2022春新款",
                "退货包运费 满30反2",
                "￥14.88"
        );
        shops.add(gril);

        Shop mango = new Shop(
                R.drawable.mango,
                "【当天发出】正宗海南小台芒",
                "满21减3 坏了包赔",
                "￥18.7"
        );
        shops.add(mango);

        Shop lens = new Shop(
                R.drawable.lens,
                "一次性擦镜纸湿巾",
                "24小时发货",
                "￥1.7"
        );
        shops.add(lens);





    }
}
















